home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / netlist.c < prev    next >
C/C++ Source or Header  |  1996-10-13  |  4KB  |  172 lines

  1. /*
  2.  * Generate the NetLink Listing of Shared Rooms.
  3.  */
  4.  
  5. #include "ctdl.h"       /*
  6.                          * header file
  7.                          */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <math.h>
  12. #include <ctype.h>
  13. #include <time.h>
  14. #include <proto/exec.h>
  15. #include <dos/dos.h>
  16. #include <pragmas/dos_pragmas.h>
  17. #include "exec/memory.h"
  18. #include "exec/ports.h"
  19. #include "exec/exec.h"
  20.  
  21. /*
  22.  *                              contents
  23.  *
  24.  *      crashout()              irrecoverable error
  25.  *      main()                  Main controller for this program
  26.  *      openFile()              opens a .sys file
  27.  */
  28.  
  29. extern rTable *roomTab;           /*
  30.  
  31.                                    * RAM index of rooms
  32.                                    */
  33. extern CONFIG cfg;                /*
  34.  
  35.                                    * A buncha variables
  36.                                    */
  37. extern FILE *netfl;
  38. extern NetBuffer netBuf;
  39. extern NetTable *netTab;
  40. extern VirtualRoom *VRoomTab;
  41. extern char VirtualInUse;
  42. extern VirtNet *VirtNetList;
  43. extern int thisNet,
  44.           VirtSize,
  45.           VNetSize;
  46. FILE     *netLog;
  47.  
  48. void CheckNet(int i, int roomSlot);
  49. void CheckVirt(int TheVirt, int NetRover);
  50.  
  51. /*
  52.  * crashout()
  53.  *
  54.  * This function handles an irrecoverable error.
  55.  */
  56. void
  57. crashout(str)
  58.   char     *str;
  59. {
  60.   exit(printf(str));
  61. }
  62.  
  63. /*
  64.  * main()
  65.  *
  66.  * This is the main controller.
  67.  */
  68. int       main(int, char **);
  69. int k_flag;
  70. int
  71. main(argc, argv)
  72.   int       argc;
  73.   char    **argv;
  74. {
  75.   SYS_FILE  netFile;
  76.   int       Index, NetRover;
  77.   cfg.weAre = UTILITY;
  78.   fprintf(stderr," Citadel Network Links List %s\n", VERSION_NAME);
  79.   if (readSysTab(FALSE, TRUE))
  80.     {
  81.       mvToHomeDisk(&cfg.homeArea);
  82.       makeSysName(netFile, "ctdlnet.sys", &cfg.netArea);
  83.       openFile(netFile, &netfl);
  84.       initNetBuf(&netBuf);
  85.       printf("\n #!netlinks %s %s\n", cfg.codeBuf + cfg.nodeName, cfg.codeBuf + cfg.nodeId);
  86.       for (Index = AIDEROOM + 1;        /*
  87.                                          * First 3 never shared
  88.                                          */
  89.            Index < MAXROOMS; Index++)
  90.         {
  91.           if (roomTab[Index].rtflags.INUSE &&
  92.               roomTab[Index].rtflags.SHARED)
  93.             {
  94.               printf(" room=%s\n", roomTab[Index].rtname);
  95.               k_flag = 0;
  96.               for( NetRover = 0; NetRover < cfg.netSize; NetRover++)
  97.                 {
  98.                 CheckNet(NetRover, Index);
  99.                 };
  100.               printf("\n");
  101.             };
  102.         };
  103.     };
  104.   VirtInit();
  105.   if (VirtualInUse)
  106.     {
  107.       for (Index = 0; Index < VirtSize; Index++)
  108.         {
  109.           if (strLen(VRoomTab[Index].vrName) != 0)
  110.             {
  111.               printf(" room=%s", VRoomTab[Index].vrName);
  112.               k_flag = 0;
  113.               for (NetRover = 0; NetRover < cfg.netSize; NetRover++)
  114.                  CheckVirt(Index, NetRover);
  115.               printf("\n");
  116.             };
  117.         };
  118.     };
  119.   printf("end_data\n");
  120. }
  121.  
  122. /*
  123.  * CheckNet()
  124.  *
  125.  * This checks to see if the given room is shared with this node and does
  126.  * the requisite print.
  127.  */
  128. void CheckNet(int i, int roomSlot)
  129. {
  130.     int j;
  131.     if (netTab[i].ntflags.in_use)
  132.       {
  133.       for (j = 0; j < SHARED_ROOMS; j++)
  134.         {
  135.         if (isSharedRoom(i, j))
  136.           {
  137.           if (netTabRoomSlot(i, j) == roomSlot &&
  138.               roomTab[roomSlot].rtgen == netGen(i, j))
  139.             {
  140.             getNet(i, &netBuf);
  141.             if( k_flag % 2 == 0 ) printf("  share=");
  142.             printf("  %s  %s ", netBuf.netName, netBuf.netId);
  143.             if( k_flag % 2 == 1 ) printf("\n");
  144.             k_flag++;
  145.             return;
  146.             }
  147.           }
  148.         }
  149.       }
  150. }
  151.  
  152. /*
  153.  * CheckVirt()
  154.  *
  155.  * This processes a virtual room.
  156.  */
  157. void CheckVirt(int TheVirt, int NetRover)
  158. {
  159.     int i;
  160.     for (i = 0; i < VIRT_LIMIT; i++) {
  161.         if (VirtNetList[NetRover].VirtList[i].WhichVirt == TheVirt) {
  162.             getNet(NetRover, &netBuf);
  163.             if (netBuf.nbflags.in_use)
  164.               {
  165.               if( k_flag % 2 == 0 ) printf("  share=");
  166.               printf("  %s  %s ", netBuf.netName, netBuf.netId);
  167.               if( k_flag % 2 == 1 ) printf("\n");
  168.               };
  169.         }
  170.     }
  171. }
  172.